package com.talent.core.protocol.mqtt.handler;

import com.talent.core.protocol.mqtt.config.Constant;
import com.talent.core.protocol.mqtt.model.request.TlMqttDisconnectReq;
import com.talent.core.protocol.mqtt.store.IMqttStore;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.AttributeKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @ClassName：ConnectHandler
 * @Author: hszhou
 * @Date: 2024/11/25 11:06
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@ChannelHandler.Sharable
public class TlMqttDisconnectHandler extends SimpleChannelInboundHandler<TlMqttDisconnectReq> {

    private static final  Logger logger = LoggerFactory.getLogger(TlMqttDisconnectHandler.class);

    private IMqttStore mqttStore;

    public TlMqttDisconnectHandler(IMqttStore mqttStore){
        this.mqttStore=mqttStore;
    }
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, TlMqttDisconnectReq msg) throws Exception {
        logger.info("进入【DISCONNECT】处理器,关闭连接");
        //断开标志位设置为true 这样就不发生遗嘱消息了
        ctx.channel().attr(AttributeKey.valueOf(Constant.DISCONNECT)).set(true);
        ctx.channel().close();
    }
}
